package com.sci99.ex.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import com.sci99.ex.model.Chapter;
import com.sci99.ex.model.Course;
import com.sci99.ex.util.MyBatisUtil;

public class ChapterService {
	static Logger log = Logger.getLogger(ChapterService.class);

	public static void saveChapter(Chapter c) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		if (c.getId() == null) {
			s.insert("addChapter", c);
		} else {
			s.update("uptChapter", c);
		}
		s.commit();
		s.close();
	}

	public static List<Chapter> getChapterList(Course c) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		List<Chapter> rs = s.selectList("getChapters", c);
		s.close();
		return rs;
	}

	public static void delChapter(Chapter c) throws Exception {
		SqlSession s = MyBatisUtil.getSession();
		s.delete("delChapter", c);
		s.commit();
		s.close();
	}
}
